package com.spring.boot.controller;

import com.spring.boot.entity.User;
import com.spring.boot.service.UserService;
import com.spring.boot.vo.ChangePasswordVO;
import com.spring.boot.vo.QueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: ZTQ
 * @Date: 2021/01/01 17:26
 * @Description: TODO 用户管理 控制器
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * @param user 用户对象
     * @description: 添加用户
     */
    @PostMapping(value = "/addUser", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> addUser(@RequestBody User user) {
        //调用用户service层的addUser方法，进行新增用户操作
        Map<String, Object> stringObjectMap = userService.addUser(user);
        //返回数据信息
        return stringObjectMap;
    }
    /**
     * @param user 用户信息
     * @description: 登录
     */
    @PostMapping(value = "/login", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> login(@RequestBody User user) {
        String idCard = user.getIdCard();
        String password = user.getPassword();
        //调用用户service层的longin方法，进行登录操作
        Map<String, Object> stringObjectMap = userService.longin(idCard, password);
        //返回数据信息
        return stringObjectMap;
    }

    /**
     * @param user 用户对象
     * @description: 修改用户
     */
    @PostMapping(value = "/updateUser", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> updateUser(@RequestBody User user) {
        //调用用户service层的updateUser方法，进行修改用户操作
        Map<String, Object> stringObjectMap = userService.updateUser(user);
        //返回数据信息
        return stringObjectMap;
    }

    /**
     * @param uid 用户id
     * @description: 批量删除用户
     */
    @GetMapping(value = "/deleteBatchIdsUser", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> deleteBatchIdsUser(@RequestParam String uid) {
        //调用用户service层的updateUser方法，进行修改用户操作
        Map<String, Object> stringObjectMap = userService.deleteBatchIdsUser(uid);
        //返回数据信息
        return stringObjectMap;
    }


    /**
     * @param user 用户对象
     * @description: 根据关键字 筛选查询用户信息
     */
    @GetMapping(value = "/getUserList",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> getUserList(QueryRequest queryRequest, User user){
        //调用用户service层的findUserList方法，进行根据关键字进行筛选查询操作
        Map<String, Object> userList = userService.findUserList(queryRequest, user);
        //返回数据信息
        return userList;
    }


    /**
     * @param uid 用户id
     * @description: 查询个人信息
     */
    @GetMapping(value = "/getPersonalInformationByUid", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> getPersonalInformationByUid(@RequestParam String uid) {
        //调用用户service层的updateUser方法，进行修改用户操作
        Map<String, Object> personalInformationByUid = userService.getPersonalInformationByUid(uid);
        //返回数据信息
        return personalInformationByUid;
    }


    /**
     * @param changePasswordVO 修改密码实体类
     * @description: 修改密码
     */
    @PostMapping(value = "/changePassword", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> changePassword(@RequestBody ChangePasswordVO changePasswordVO) {
        //调用用户service层的changePassword方法，进行修改密码
        Map<String, Object> stringObjectMap = userService.changePassword(changePasswordVO);
        //返回数据信息
        return stringObjectMap;
    }

    /**
     * @param role 用户权限
     * @description: 查询菜单
     */
    @GetMapping(value = "/findMenu", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> findMenu(@RequestParam String role) {
        //调用用户service层的findMenu方法，进行查询菜单操作
        Map<String, Object> menu = userService.findMenu(role);
        //返回数据信息
        return menu;
    }
}
